package cn.wolfcode.shop.cloud.mq;

import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.annotation.SelectorType;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.Message;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Component;

import java.util.Map;

@RocketMQMessageListener(
        consumerGroup = MQConstans.CREATE_ORDER_SUCCESS_GROUP,
        topic = MQConstans.CREATE_ORDER,
        selectorExpression = MQConstans.CREATE_ORDER_SUCCESS_TAG

)

@Component
public class OrderSuccessMQListener implements RocketMQListener<Map> {

    @Autowired
    private RocketMQTemplate rocketMQTemplate;
    @Override
    public void onMessage(Map  map) {
        System.out.println("进入到成功的消费者中");
        //成功以后需要再次发送一个延迟消息
        //并不是在成功的队列中直接去检查订单是否有支付
        //真实在公司业务比较复杂
        MessageBuilder<Map> mapMessageBuilder =MessageBuilder.withPayload(map);
        //支持特定的level（延迟级别）,比如定时1秒,5秒、10秒、1m等。此时设置延时等级3级,延时10秒,1级为1秒
        rocketMQTemplate.syncSend(MQConstans.CREATE_ORDER_DELAY_DEST, mapMessageBuilder.build(),5000,16);
    }





}